package com.metal.gear.certification.entity.vo.permission;

import com.metal.gear.certification.entity.po.SysPermission;
import com.metal.gear.common.util.tree.SzlTreeNode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(name ="菜单路由实体")
public class PermissionMenuVo extends SzlTreeNode<String, PermissionMenuVo> {

    @Schema(name ="菜单名称")
    private String name;
    @Schema(name ="是否路由")
    private Boolean isRoute;
    @Schema(name ="路由地址")
    private String url;
    @Schema(name ="排序码")
    private Double sortNo;
    @Schema(name ="重定向路径，用于系统之外页面跳转，redirect存在则isRoute和url均为null")
    private String redirect;
    @Schema(name ="排序码")
    private Integer menuType;


    public static PermissionMenuVo convertFrom(SysPermission permission){
        PermissionMenuVo vo = new PermissionMenuVo();
        BeanUtils.copyProperties(permission,vo);
        vo.setId(permission.getId());
        vo.setIsRoute(permission.isRoute());
        vo.setWeight(permission.getSortNo());
        return vo;
    }

    public static SysPermission TranslateTo(PermissionMenuVo vo){
        SysPermission po = new SysPermission();
        BeanUtils.copyProperties(vo,po);
        return po;
    }





}
